﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportServiceRef;
    using WMS6.Web.UserControls;

    public class LocationInventoryRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15246;
        protected GridView gvLocationInventoryRpt;
        protected HtmlInputHidden hdnFrom;
        protected HtmlHead Head1;
        protected Label lblIdleInventoryRptList;
        protected Label lblMsg;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        protected UpdatePanel up1;

        private void BindData2LocationInventoryRptList(InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(invLocSkyTransRptQueryEntity.CurrentPage);
            DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetInvLocSkyTransRptDataSet(invLocSkyTransRptQueryEntity);
            base.BindData2GridView(this.gvLocationInventoryRpt, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
            invLocSkyTransRptQueryEntity.IsGetAll = true;
            string currentPageIndex = invLocSkyTransRptQueryEntity.CurrentPage;
            invLocSkyTransRptQueryEntity.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetInvLocSkyTransRptDataSet(invLocSkyTransRptQueryEntity))
                {
                    base.Export2Excel("LocationInventoryRpt.xls", "15246", this.gvLocationInventoryRpt, ds);
                }
            }
            finally
            {
                invLocSkyTransRptQueryEntity.IsGetAll = false;
                invLocSkyTransRptQueryEntity.CurrentPage = currentPageIndex;
                this.SetInvLocSkyTransRptQueryEntity(invLocSkyTransRptQueryEntity);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
            invLocSkyTransRptQueryEntity.CurrentPage = "0";
            this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
            invLocSkyTransRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
            invLocSkyTransRptQueryEntity.OWNER_ID = "";
            invLocSkyTransRptQueryEntity.VENDOR_ID = "";
            invLocSkyTransRptQueryEntity.BEGIN_DATE = DateTime.Today.AddDays(-1.0);
            invLocSkyTransRptQueryEntity.END_DATE = DateTime.Today;
            invLocSkyTransRptQueryEntity.SHOW_DAMAGE_5DAYS = false;
            invLocSkyTransRptQueryEntity.INSERT_DAILY_DATA = false;
            this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
            if (int.Parse(invLocSkyTransRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                invLocSkyTransRptQueryEntity.CurrentPage = (int.Parse(invLocSkyTransRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
            if (int.Parse(invLocSkyTransRptQueryEntity.CurrentPage) > 0)
            {
                invLocSkyTransRptQueryEntity.CurrentPage = (int.Parse(invLocSkyTransRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
            this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            base.Server.Transfer("LocationInventoryRptQuery.aspx", false);
        }

        private InvLocSkyTransRptQueryEntity GetInvLocSkyTransRptQueryEntity()
        {
            return (base.PageQueryEntitySession as InvLocSkyTransRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
                invLocSkyTransRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
            }
        }

        protected void gvLocationInventoryRpt_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15246", this.gvLocationInventoryRpt);
        }

        protected void gvLocationInventoryRpt_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
            }
        }

        protected void gvLocationInventoryRpt_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = this.GetInvLocSkyTransRptQueryEntity();
                invLocSkyTransRptQueryEntity.SortField = e.SortExpression;
                if (invLocSkyTransRptQueryEntity.SortDirection == "ASC")
                {
                    invLocSkyTransRptQueryEntity.SortDirection = "DESC";
                }
                else if (invLocSkyTransRptQueryEntity.SortDirection == "DESC")
                {
                    invLocSkyTransRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity = new InvLocSkyTransRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    invLocSkyTransRptQueryEntity.OWNER_ID = this.PreviousPage.OwnerID;
                    invLocSkyTransRptQueryEntity.VENDOR_ID = this.PreviousPage.VendorID;
                    invLocSkyTransRptQueryEntity.BEGIN_DATE = DateTime.Parse(this.PreviousPage.StartTime);
                    invLocSkyTransRptQueryEntity.END_DATE = DateTime.Parse(this.PreviousPage.EndTime);
                    invLocSkyTransRptQueryEntity.SHOW_DAMAGE_5DAYS = this.PreviousPage.ShowDamage5Days;
                    invLocSkyTransRptQueryEntity.INSERT_DAILY_DATA = false;
                }
                else
                {
                    invLocSkyTransRptQueryEntity.OWNER_ID = "";
                    invLocSkyTransRptQueryEntity.VENDOR_ID = "";
                    invLocSkyTransRptQueryEntity.BEGIN_DATE = DateTime.Today.AddDays(-1.0);
                    invLocSkyTransRptQueryEntity.END_DATE = DateTime.Today;
                    invLocSkyTransRptQueryEntity.SHOW_DAMAGE_5DAYS = false;
                    invLocSkyTransRptQueryEntity.INSERT_DAILY_DATA = false;
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            invLocSkyTransRptQueryEntity.IsGetAll = false;
            invLocSkyTransRptQueryEntity.CurrentPage = "0";
            invLocSkyTransRptQueryEntity.PageSize = this.gvLocationInventoryRpt.PageSize.ToString();
            invLocSkyTransRptQueryEntity.SortField = "OWNER_ID";
            invLocSkyTransRptQueryEntity.SortDirection = "DESC";
            this.PagerFooter.PageSize = this.gvLocationInventoryRpt.PageSize;
            this.SetInvLocSkyTransRptQueryEntity(invLocSkyTransRptQueryEntity);
            this.BindData2LocationInventoryRptList(invLocSkyTransRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetInvLocSkyTransRptQueryEntity(InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity)
        {
            base.PageQueryEntitySession = invLocSkyTransRptQueryEntity;
        }

        public LocationInventoryRptQuery PreviousPage
        {
            get
            {
                return (LocationInventoryRptQuery) base.PreviousPage;
            }
        }
    }
}

